﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using DeepEarth.Map.Core;
using DeepEarth.Core;
using DeepEarth.Toolkit.Geometry.Data;
using System.Windows.Media.Imaging;

namespace ExampleApplication.Examples
{
    public partial class AddFeatures_Code : Page
    {
        public AddFeatures_Code()
        {
            InitializeComponent();
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            AddGeometries();
        }

        void AddGeometries()
        {
            Layer myLayer = new Layer();

            DeepEarth.Toolkit.Geometry.Polygon pg = new DeepEarth.Toolkit.Geometry.Polygon();
            pg.OuterRing.Add(new Location(10, -10));
            pg.OuterRing.Add(new Location(10, 10));
            pg.OuterRing.Add(new Location(-10, 10));
            pg.OuterRing.Add(new Location(-10, -10));
            pg.OuterRing.Add(new Location(10, -10));

            pg.Fill = new SolidColorBrush(Colors.Red);

            myLayer.Add(pg);

            DeepEarth.Toolkit.Geometry.LineString ls = new DeepEarth.Toolkit.Geometry.LineString();
            ls.Locations.Add(new Location(-50, -150));
            ls.Locations.Add(new Location(-15, 0));
            ls.Locations.Add(new Location(-15, 150));
            ls.Stroke = new SolidColorBrush(Colors.Yellow);
            ls.StrokeThickness = 5;

            myLayer.Add(ls);

            DeepEarth.Toolkit.Geometry.Pushpin pp = new DeepEarth.Toolkit.Geometry.Pushpin();
            pp.Position = new Location(51, 0);
            pp.PositionOrigin = new PositionOrigin(0.5, 1.0);

            myLayer.Add(pp);

            DeepEarth.Toolkit.Geometry.Pushpin imagePushpin = new DeepEarth.Toolkit.Geometry.Pushpin();
            imagePushpin.Position = new Location(30, 30);
            imagePushpin.PositionOrigin = new PositionOrigin(1.0 / 6.0, 1.0);
            Image image = new Image();
            string host = Application.Current.Host.Source.AbsoluteUri.Replace(Application.Current.Host.Source.AbsolutePath, "");
            image.Source = new BitmapImage(new Uri(host + "/Images/flag-blue.png"));
            imagePushpin.Content = image;
            imagePushpin.Scale = 2;

            myLayer.Add(imagePushpin);

            TextBlock block = new TextBlock();
            block.Text = "This is a text block";
            block.Foreground = new SolidColorBrush(Colors.Red);
            block.FontSize = 12;
            block.SetValue(Layer.PositionProperty, new Location(-30, 30));
            block.SetValue(Layer.PositionOriginProperty, new PositionOrigin(0.5, 0.5));

            myLayer.Add(block);

            this.map.Children.Add(myLayer);

            Layer useStatic = new Layer { UseVectorLayer = true };
            DeepEarth.Toolkit.Geometry.Polygon pg2 = new DeepEarth.Toolkit.Geometry.Polygon();
            pg2.OuterRing.Add(new Location(30, -30));
            pg2.OuterRing.Add(new Location(30, -25));
            pg2.OuterRing.Add(new Location(25, -25));
            pg2.OuterRing.Add(new Location(25, -30));
            pg2.OuterRing.Add(new Location(30, -30));

            pg2.Fill = new SolidColorBrush(Colors.Green);
            useStatic.Add(pg2);

            this.map.Children.Add(useStatic);
        }
    }
}
